package com.doraro.coal.moudle.purch.controller;

import com.doraro.coal.moudle.purch.entity.PurchApply;
import com.doraro.coal.moudle.purch.entity.PurchExec;
import com.doraro.coal.moudle.purch.entity.PurchSupplier;
import com.doraro.coal.moudle.purch.service.IPurchApplyService;
import com.doraro.coal.moudle.purch.service.IPurchExecService;
import com.doraro.coal.moudle.purch.service.IPurchSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @author doraro
 * @since 2019-09-30 16:51
 */
@Controller
public class PurchExecController {
    @Autowired
    private IPurchExecService execService;
    @Autowired
    private IPurchSupplierService supplierService;
    @Autowired
    private IPurchApplyService applyService;

    @GetMapping("/queryPE")
    public String queryPE() {
        return "purchaseExecute/queryPE";
    }

    @GetMapping("/PE/view/{id}")
    public String viewPeDetail(@PathVariable Long id, Model model) {
        final PurchExec exec = execService.getById(id);
        final List<PurchSupplier> suppliers = supplierService.lambdaQuery()
                .eq(PurchSupplier::getExecId, exec.getId()).list();
        final PurchApply apply = applyService.getById(exec.getPurchApplyId());
        model.addAttribute("suppliers", suppliers);
        model.addAttribute("p", apply);
        return "purchaseExecute/dispPEDetails";
    }
    @GetMapping("/PE/update/{id}")
    public String updatePeDetail(@PathVariable Long id, Model model) {
        final PurchExec exec = execService.getById(id);
        final List<PurchSupplier> suppliers = supplierService.lambdaQuery()
                .eq(PurchSupplier::getExecId, exec.getId()).list();
        final PurchApply apply = applyService.getById(exec.getPurchApplyId());
        model.addAttribute("suppliers", suppliers);
        model.addAttribute("p", apply);
        return "purchaseExecute/fillPE";

    }
}
